package com.example.food_contract_system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.food_contract_system.domain.Food;
import com.example.food_contract_system.domain.FoodRecommed;
import com.example.food_contract_system.domain.Rotation;
import com.example.food_contract_system.mapper.FoodMapper;
import com.example.food_contract_system.service.FoodRecommedService;
import com.example.food_contract_system.mapper.FoodRecommedMapper;
import com.example.food_contract_system.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
* @author Lhy
* @description 针对表【food_recommed】的数据库操作Service实现
* @createDate 2023-07-14 14:34:07
*/
@Service
public class FoodRecommedServiceImpl extends ServiceImpl<FoodRecommedMapper, FoodRecommed> implements FoodRecommedService{

    @Autowired
    private FoodRecommedMapper foodRecommedMapper;
    @Autowired
    private FoodMapper foodMapper;

    @Override
    public R insertRecommend(String fId, String status) {
        //1.首先判断是展示还是取消展示
        if (status.equals("0")){
            // 取消展示
            foodMapper.updateStatus("1",fId);
            return R.ok().put("msg","取消成功!");
        }else{
            // 展示
            // 判断是否已经六张图片
            List<Food> foods = foodMapper.selectList(new QueryWrapper<Food>()
                    .eq("f_recommend_status", "0"));
            if (foods.size() == 5){
                return R.error(500,"只能展示五张图片");
            }
            // 低于六张，可以对图片进行展示处理
            foodMapper.updateStatus("0",fId);

            return R.ok().put("msg","添加成功!");
        }
    }

    @Override
    public R getRecommend() {
        List<Food> foods = foodMapper.selectList(new QueryWrapper<Food>().eq("f_recommend_status", "0"));
        if (foods.size()>0){
            return R.ok().put("data",foods);
        }
        return R.error();
    }
}




